package pers.wq.controller.student;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

import pers.wq.controller.BaseIndexAction;
import pers.wq.controller.PublicListAction;
import pers.wq.model.StudentModel;
import pers.wq.model.bean.BaseBean;
import pers.wq.model.bean.Major;
import pers.wq.model.bean.SelectMajor;
import pers.wq.model.bean.Student;
import pers.wq.util.TagManager;

public class IndexAction extends PublicListAction{
	public static String STUDENT_LOGIN_TAG = "STUDENT_LOGIN";
	private Student user;
	private StudentModel stuModel;
	private Major major;
	private SelectMajor selectMajor;
	private BaseBean[] objs;
	public IndexAction() {
		// TODO Auto-generated constructor stub
		super("student");
		setLoginTag(STUDENT_LOGIN_TAG);
		setXmlPath("thList4student.xml");
		System.out.println("student IndexAction");
		stuModel = new StudentModel();
		System.out.println("student IndexAction2");
	}
	public String index() {
		return SUCCESS;
	}
	public String login() {
		// TODO Auto-generated method stub
		System.out.println("student IndexAction login");
		String reStr = ERROR;
		user = stuModel.checkLogin(user);
		if(null != user) {
			this.loginSession(user.getId());
			reStr = SUCCESS;
		}
		return reStr;
	}
	@Override
	public String formTag() {
		// TODO Auto-generated method stub
		System.out.println("student IndexAction forTag");
		return TagManager.formTag(getDataListId(),"student",getMethod());
	}
	@Override
	public Map<String, String> mapTag() {
		// TODO Auto-generated method stub
		System.out.println("student IndexAction mapTag");
		for (int i = 0 ; i < objs.length ; i++) {
			BaseBean baseBean = objs[i];
			System.out.println("student IndexAction mapTag for");
			if(null != baseBean){
				System.out.println("_mapTag" + baseBean);
				return baseBean.tagMap4Stu();
			}
		}
		return null;
	}
	@Override
	public String add() throws Exception {
		// TODO Auto-generated method stub
		BaseBean[] objs = {major,selectMajor};
		String reStr = this._add(objs);
		return reStr == SUCCESS ? CHAIN : ERROR;
	}
	@Override
	public String se() throws Exception {
		// TODO Auto-generated method stub
		System.out.println("Student se");
		objs = new BaseBean[]{major,selectMajor,user};
		String reStr = _se(objs)  == EA ? super.se() : ERROR;
		return reStr;
	}
	@Override
	public String sa() throws Exception {
		// TODO Auto-generated method stub
		System.out.println("User IndexAction sa");
		objs = new BaseBean[]{major,selectMajor};
		return super.sa();
	}
	@Override
	public String update() throws Exception {
		// TODO Auto-generated method stub
		BaseBean[] objs = {major,selectMajor};
		String reStr = this._update(objs);
		return reStr == SUCCESS ? CHAIN : ERROR;
	}
	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		BaseBean[] objs = {major,selectMajor};
		System.out.println("delete in");
		try{
			if(this._delete(objs).equals(SUCCESS)){
				this.setJsonMapSuccess("Delete success!");
			}else{
				this.setJsonMapError("Delete error!");
			}
		}catch(Exception e){
			this.setJsonMapError("Delete error");
		}
		System.out.println(jsonMap);
		return JSON;
	}
	public Student getUser() {
		System.out.println("Student IndexAction getUser");
		return user;
	}
	public void setUser(Student user) {
		System.out.println("Student IndexAction setUser");
		this.user = user;
	}
	public Major getMajor() {
		return major;
	}
	public void setMajor(Major major) {
		this.major = major;
	}
	public SelectMajor getSelectMajor() {
		return selectMajor;
	}
	public void setSelectMajor(SelectMajor selectMajor) {
		this.selectMajor = selectMajor;
	}
}
